package com.splic.web.controller.product;

import java.util.List;
import com.splic.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.splic.common.annotation.Log;
import com.splic.common.enums.BusinessType;
import com.splic.product.domain.UserMotionRankingCountry;
import com.splic.product.service.UserMotionRankingCountryService;
import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.AjaxResult;
import com.splic.common.utils.poi.ExcelUtil;
import com.splic.common.core.page.TableDataInfo;

/**
 * 用户运动量全国排名统计Controller
 * 
 * @author singe
 * @date 2022-02-16
 */
@Controller
@RequestMapping("/userMotionRanking/country")
public class UserMotionRankingCountryController extends BaseController
{
    private String prefix = "motionRankingCountry";

    @Autowired
    private UserMotionRankingCountryService userMotionRankingCountryServiceImpl;

    @RequiresPermissions("product:country:view")
    @GetMapping()
    public String country()
    {
        return prefix + "/list";
    }

    /**
     * 查询用户运动量全国排名统计列表
     */
    @RequiresPermissions("product:country:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserMotionRankingCountry userMotionRankingCountry)
    {
        startPage();
        List<UserMotionRankingCountry> list = userMotionRankingCountryServiceImpl.selectUserMotionRankingCountryList(userMotionRankingCountry);
        return getDataTable(list);
    }

    /**
     * 新增用户运动量全国排名统计
     */
    @GetMapping(value = { "/form/{id}", "/form" })
    public String form(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id)){
            mmap.put("userMotionRankingCountry", userMotionRankingCountryServiceImpl.selectUserMotionRankingCountryById(id));
        }else{
            mmap.put("userMotionRankingCountry", new UserMotionRankingCountry());
        }
        return prefix + "/form";
    }


    /**
     * 新增保存用户运动量全国排名统计
     */
    @RequiresPermissions("product:country:edit")
    @Log(title = "用户运动量全国排名统计", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(UserMotionRankingCountry userMotionRankingCountry)
    {
        return toAjax(userMotionRankingCountryServiceImpl.saveOrUpdate(userMotionRankingCountry));
    }

    /**
     * 删除
     */
    @RequiresPermissions("product:country:remove")
    @Log(title = "用户运动量全国排名统计", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id)
    {
        return toAjax(userMotionRankingCountryServiceImpl.deleteById(id));
    }


    /**
     * 导出用户运动量全国排名统计列表
     */
    @RequiresPermissions("product:country:export")
    @Log(title = "用户运动量全国排名统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserMotionRankingCountry userMotionRankingCountry)
    {
        List<UserMotionRankingCountry> list = userMotionRankingCountryServiceImpl.selectUserMotionRankingCountryList(userMotionRankingCountry);
        ExcelUtil<UserMotionRankingCountry> util = new ExcelUtil<UserMotionRankingCountry>(UserMotionRankingCountry.class);
        return util.exportExcel(list, "用户运动量全国排名统计数据");
    }

}
